package hn.cch.indicator;

import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;

import java.util.List;
import java.util.stream.Collectors;

public class M2 implements Indicator {
    @Override
    public Double indicator(List<Return> R) {
        Double meanRiskFree = R.stream().collect(Collectors.averagingDouble(Return::getRf));

        Double sharpe = new Sharpe().indicator(R);

        double[] Rp = R.stream().map(Return::getRp).mapToDouble(Double::doubleValue).toArray();
        double sigmaBenchmark = new StandardDeviation(false).evaluate(Rp);

        Double m2 = meanRiskFree + sharpe * sigmaBenchmark;
        return m2;
    }
}
